﻿using Microsoft.EntityFrameworkCore;
using MiniErp.Common.DB.MySqlDB;
using MiniErp.Entity.DataStreams.DOs.AssetManagement;
using MiniErp.Repository.BaseRepository;
using MiniErp.Repository.MysqlRepository.IRepository.AssetManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MiniErp.Repository.MysqlRepository.Repository.AssetManagement
{
    public class AssetModificationRecordRepository : BaseRepository<MysqlContext, AssetModificationRecord>, IAssetModificationRecordRepository
    {
        public AssetModificationRecordRepository(MysqlContext mysqlContext) : base(mysqlContext) { }

        public async Task<List<AssetModificationRecord>> GetAllRecordAsync(DateTime startTime, DateTime endTime, int Page, int num)
        {
            return await _set
                  .Where(item => item.RecordTime >= startTime && item.RecordTime <= endTime)
                  .OrderBy(item => item.AMRId)
                  .Skip((Page - 1) * num)
                  .Take(num)
                  .ToListAsync();
        }

        public async Task<List<AssetModificationRecord>> GetFuzzyRecordAsync(string value, DateTime startTime, DateTime endTime, int Page, int num)
        {
            return await _set
                  .Where(item => item.RecordTime >= startTime
                  && item.RecordTime <= endTime
                  && (item.AllId.Contains(value)
                  || item.assetModificationType.AMTName.Contains(value)
                  || item.AdminIdName.Contains(value)
                  || item.UserName.Contains(value)
                  || item.AssetStateName.Contains(value)
                  || item.PositionName.Contains(value)))
                  .OrderBy(item => item.AMRId)
                  .Skip((Page - 1) * num)
                  .Take(num)
                  .ToListAsync();
        }
    }
}
